package com.ysu.his.admin.controller;

import com.github.pagehelper.PageInfo;
import com.ysu.his.admin.service.DepartmentService;
import com.ysu.his.dto.DepartmentDto;
import com.ysu.his.entity.user.Department;
import com.ysu.his.dto.UserDepartmentDto;
import com.ysu.his.vo.UserVo;
import com.ysu.his.vo.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/api/admin/department")
public class DepartmentController
{
    @Autowired
    private DepartmentService departmentService;

    @GetMapping(value = "/getDepartmentByPage/{page}/{limit}")
    public Result getDepartmentByPage(@PathVariable("page") Integer page,
                                      @PathVariable("limit") Integer limit,
                                      DepartmentDto departmentDto)
    {
        PageInfo<Department> pageInfo = departmentService.getDepartmentByPage(page,limit,departmentDto);
        return Result.ok(pageInfo);
    }

    @PostMapping(value = "/addDepartment")
    public Result addDepartment(@RequestBody Department department)
    {
        departmentService.addDepartment(department);
        return Result.ok(null);
    }

    @GetMapping(value = "/getDoctorByDepartmentId/{id}")
    public Result getDoctorByDepartmentId(@PathVariable("id") Long departmentId)
    {
        List<UserVo> userVoList = departmentService.getDoctorByDepartmentId(departmentId);
        return Result.ok(userVoList);
    }

    @PostMapping(value = "/addDoctorToDepartment")
    public Result addDoctorToDepartment(@RequestBody UserDepartmentDto userDepartmentDto)
    {
        departmentService.addDoctorToDepartment(userDepartmentDto);

        return Result.ok(null);
    }

    @GetMapping(value = "/getAllDepartment")
    public Result<List<Department>> getAllDepartment()
    {
        List<Department> departmentList = departmentService.getAllDepartment();
        return Result.ok(departmentList);
    }
}
